package cn.wit.sst.ml.kmeans;

/**
 * 欧几里得距离计算
 *
 */
public class EuclideanDistanceStrategy implements DistanceStrategy {
	@Override
	public double measure(Sample p1, Sample p2) {
		double[] attrs1 = p1.getAttrs();
		double[] attrs2 = p2.getAttrs();

		assert (attrs1.length == attrs2.length);

		double sum = 0;
		for (int i = 0; i < attrs1.length; i++) {
			sum += Math.pow(attrs1[i] - attrs2[i], 2);
		}

        return Math.sqrt(sum);
	}
}
